<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>登录</title>
    <script type="text/javascript" src="../js/jquery.min.js" ></script>

    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">

    <!-- Custom fonts for this template-->
    <link href="vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">
    <link
            href="https://fonts.googleapis.com/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i"
            rel="stylesheet">

    <!-- Custom styles for this template-->
    <link href="css/sb-admin-2.min.css" rel="stylesheet">
    <link href="//netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
</head>

<!--
<body>
<form id="form1" onsubmit="return false" action="##" >
    账号<input type="text" name="name" id="name"/><br>
	账号<input type="text" name="name" id="name" class="form-control form-control-user"
			 aria-describedby="emailHelp" placeholder="请输入用户名...">
    密码<input type="text" name="password" id="password" class="form-control form-control-user"
			 aria-describedby="emailHelp" placeholder="请输入用户密码..."/><br>
    <input type="button" value="提交" onclick="login()" class="btn btn-primary btn-user btn-block">
    <a href="register.html">注册</a>
</form>
</body>
-->
<body class="bg-gradient-primary" onkeydown="if(event.keyCode==13){login_btn.click()}">

<div class="container">

    <!-- Outer Row -->
    <div class="row justify-content-center">

        <div class="col-xl-10 col-lg-12 col-md-9">

            <div style="width: 900px; display: block; margin: 0 auto" class="card o-hidden border-0 shadow-lg my-5">
                <div class="card-body p-0">
                    <!-- Nested Row within Card Body -->
                    <div class="row">
                        <div class="col-lg-6 d-none d-lg-block" >
                            <img src="photo/login.jpg" height="100%" width="105%">
                        </div>
                        <!--							class="col-lg-6 d-none d-lg-block bg-login-image"-->
                        <div class="col-lg-6">
                            <div class="p-5">
                                <div class="text-center">
                                    <h1 class="h4 text-gray-900 mb-4">欢迎来到校园二手交易系统！</h1>
                                </div>
                                <form class="user" id="form1" onsubmit="return false" action="##" >
                                    <div class="form-group">
                                        <input type="text" name="account" id="account" style="font-size: 18px" class="form-control form-control-user"
                                               placeholder="请输入用户名...">
                                    </div>
                                    <div class="form-group">
                                        <input type="password" name="password" id="password" style="font-size: 18px" class="form-control form-control-user"
                                               placeholder="请输入用户密码..."/>
                                    </div>

                                    <input type="button" value="登录" onclick="login()" style="font-size: 18px" class="btn btn-primary btn-user btn-block" id="login_btn">
                                </form>
                                <hr>
                                <br>
                                <div class="text-center">
                                    <a style="font-size: 15px" href="register.html">注册成为新用户</a>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

        </div>

    </div>

</div>
<!-- Bootstrap core JavaScript-->
<script src="vendor/jquery/jquery.min.js"></script>
<script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>

<!-- Core plugin JavaScript-->
<script src="vendor/jquery-easing/jquery.easing.min.js"></script>

<!-- Custom scripts for all pages-->
<script src="js/sb-admin-2.min.js"></script>

</body>

<script>
    function login() {
        var loginInfo={
            account :  $("#account").val(),
            password :  $("#password").val()
        }
        $.ajax({
            url: 'user/user-server/login',
            method: 'POST',
            dataType: 'json',
            contentType : 'application/json; charset=UTF-8',
            data: JSON.stringify(loginInfo),
            success: function (result) {
                console.log(result);//打印服务端返回的数据(调试用)
                if (result.status == 200) {
                    sessionStorage.removeItem("userInfo");
                    // 转为json保存在session loginVO
                    sessionStorage.setItem("userInfo", JSON.stringify(result.data));
                    if(result.data.role == 1){
                        window.location.href = 'goodsList.html';
                    } else if(result.data.role == 2){
                        window.location.href = 'adminGoodsList.html';
                    }
                }
                else{
                    alert(result.msg)
                }
            },
        })
    }
</script>
</html>